package com.xiaotou.weibo;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xiaotou.db.pojo.WbUser;
import com.xiaotou.weibo.appData.AbstractAppOauthData;

public abstract class OauthUtils {
	static Log logger = LogFactory.getLog(OauthUtils.class);

	public abstract String getAuthrizeURL(AbstractAppOauthData appOauthData,
			HttpServletRequest request);

	public abstract WbUser storeAccessTokenAndAccessTokenSecret(
			AbstractAppOauthData appOauthData);

	public abstract void sycToopoosSource(AbstractAppOauthData appOauthData)
			throws Exception;

	protected abstract String getCallbackUrl(HttpServletRequest request);

	protected byte[] readFileImage(String filename) throws IOException {
		BufferedInputStream bufferedInputStream = new BufferedInputStream(
				new FileInputStream(filename));
		int len = bufferedInputStream.available();
		byte[] bytes = new byte[len];
		int r = bufferedInputStream.read(bytes);
		if (len != r) {
			bytes = null;
			throw new IOException("error when read file");
		}
		bufferedInputStream.close();
		return bytes;
	}

}
